package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import business.Utilisateur;

import com.cedarsoftware.util.io.JsonWriter;

import dao.DaoUtilisateur;


public class S_UserTopTenRatio extends HttpServlet {
	private static final long serialVersionUID = 1L;


	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("json");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		
		List<Utilisateur> utilisateurs = DaoUtilisateur.getTopTenRatio();
		if(utilisateurs != null && !utilisateurs.isEmpty())
			out.print(JsonWriter.objectToJson(utilisateurs));
		else
			out.print("{}");
		
		out.close();
	}
}